approximate.m
Finds mixing probabilities to approximate a given c.d.f. of a symmetric distribution,
with a mixture of uniform distributions,
Contents
Set up the problem's parameters.
This section first checks to see if the parameters of the problem are defined in the structure approximateARG . If this does not exist, then it defines them.
if exist('approximateARG','var') F=approximateARG.F; %Handle to anonymous function defining approximated c.d.f. Frange=approximateARG.Frange; %Half of the width of symmetric support for F. k=approximateARG.k; %Number of approximating uniform distributions to use. if k/2==round(k/2); error('approximate.m k must be odd.') end else F=@(x) (1+erf(x/sqrt(2)))./2; %Standard normal c.d.f. Frange=5; k=9; end
Set up the vector of mixing distributions.
Each element of rangeVec gives half of the support for a uniform distribution centered at zero.
rangeVec=(Frange/k):(Frange/k):Frange; if ~exist('approximateARG','var') rangeVec end %Set up the uniform c.d.f. %x(:,1) is the c.d.f. argument, x(:,2)=rangeVec=half range. g=@(x) (-x(:,2)<x(:,1)).*(x(:,1)<x(:,2)).*(x(:,1)+x(:,2))./(2*x(:,2))+(x(:,1)>=x(:,2));
rangeVec = 0.5556 1.1111 1.6667 2.2222 2.7778 3.3333 3.8889 4.4444 5.0000
Set up the vector of approximation points.
On these points, the approximation is exact by construction.
y=-Frange*(k-1)/k:Frange/k:0; if ~exist('approximateARG','var') y end
y = -4.4444 -3.8889 -3.3333 -2.7778 -2.2222 -1.6667 -1.1111 -0.5556 0
Set up the linear equations characterizing
f=F(y'); %Value of the true c.d.f. at the approximation points gargs=[kron(y',ones(k,1)) kron(ones(k,1),rangeVec')]; gvec=g(gargs); %Values of the approximating c.d.f.'s at the approximation points. gmat=reshape(gvec,k,k); %Each column of gmat corresponds to one approximation point, each row corresponds to an approximating distribution.
Calculate mixing probabilities & construct approximation.
mixProb=inv(gmat')*f; if ~exist('approximateARG','var') mixProb end Fhat= @(x) mixProb'*g([x*ones(k,1) rangeVec']);
mixProb = 0.1095 0.2821 0.3049 0.1941 0.0809 0.0231 0.0047 0.0007 0.0001
Plot a comparison.
if ~exist('approximateARG','var') x=-Frange:0.001:Frange; y1=zeros(size(x)); y2=zeros(size(x)); for i=1:max(size(x)); y1(i)=F(x(i)); y2(i)=Fhat(x(i)); end plot(x,y1,'-k'); hold; plot(x,y2,'-.r'); legend('Original Distribution','Approximation','Location','NorthWest'); end
Current plot held
